package com.example.mymatch.service.Imp;


import com.example.mymatch.dao.IRole;
import com.example.mymatch.model.Role;
import com.example.mymatch.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：吴茂景
 */
@Service
public class IRoleServiceImpl implements IRoleService {

    @Autowired
    private IRole roleMapper;   //对后端数据操作某张表的定义规范 编写者：吴茂景

    @Override//添加方法
    public int insertRole(Role role){
        int roleValue=0;
        //查看当前部门名称不能重复
        Role role1=new Role();
        role1.setRoleName(role.getRoleName());
        List<Role> getC=roleMapper.getAllRole(role1);
        if (getC.size()>=1){
            //不可以添加部门名称
            roleValue=-1;
        }else {
            roleValue=roleMapper.insertRole(role);
        }
        return roleValue;
    }

    @Override
    public List<Role> getAllRole(Role role){
        return roleMapper.getAllRole(role);
    }

    @Override
    public int updateRole(Role role){
        int roleValue=0;
        //判断主键不能为0
        if (role.getId()!=0){
            //主键信息必修存在

            //名称不能重复

            roleValue=roleMapper.updateRole(role);
        }
        return roleValue;
    }

    @Override
    public  int deleteRole(Role role){
        int roleValue=0;
        //判断主键不能为0
        if (role.getId()!=0){
            //主键是否有其他表有关联，如果关联，则先删除其他表的信息，或者给出此条信息不允许被删除


            roleValue=roleMapper.deleteRole(role);
        }
        return roleValue;
    }

    //单条查询
    @Override
    public Role getRole(Role role){
        Role role1=new Role();
        if (role.getId()!=0){
            role1=roleMapper.getRole(role);
        }
        return role1;
    }
}
